/**
* @author als31@aber.ac.uk
*/


#ifndef CAPTUREDEVICE_H
#define CAPTUREDEVICE_H

#include <OpenNI.h>
#include <iostream>
#include <QObject>

enum DeviceSatus
{
    INITIALIZING,
    READY,
    STREAMING,
    CLOSED
};

enum StreamSource{
    DEPTH_SENSOR,
    COLOR_SENSOR
};

class CaptureDeviceListener : public QObject, public openni::VideoStream::NewFrameListener
{
    Q_OBJECT

    void onNewFrame(openni::VideoStream&);

public:

signals:
    void newFrame(const void*, int, int , StreamSource);

};

class CaptureDevice
{

    openni::Device _captureDevice;
    openni::VideoStream _depthStream;
    openni::VideoStream _colorStream;
    DeviceSatus _status;
    CaptureDeviceListener* _depthFrameListener ;
    CaptureDeviceListener* _colorFrameListener ;

    static int _activeDevice;
    static openni::Array<openni::DeviceInfo> avalaibleDevices;

    static int isDeviceDetected(const char* deviceURI, int* index);

public:

    CaptureDevice();
    CaptureDevice(const char* deviceURI);
    CaptureDevice(const CaptureDevice& cd);
    ~CaptureDevice();

    static int initialize();
    void startStream();
    void stopStream();

    openni::Device& getDevice(){return _captureDevice;}
    openni::VideoStream& getDepthStream(){return _depthStream;}
    openni::VideoStream& getColorStream(){return _colorStream;}
    CaptureDeviceListener* getColorFrameListener(){return _colorFrameListener;}
    CaptureDeviceListener* getDepthFrameListener(){return _depthFrameListener;}

};



#endif // CAPTUREDEVICE_H
